function ListUI(options){
	return this._init(options);
}
$.extend(ListUI,{
	currentData:null,
	defaults:{
		add:{url:null,width:'400px',height:'320px',beforeAdd:null},//新增参数
		edit:{url:null,width:'400px',height:'320px',beforeEdit:null},//编辑参数
		view:{url:null,width:'400px',height:'320px',beforeView:null},//查看参数
		
		gridRender:null,//表格渲染
		gridOptions:{
			allowUnSelectRow:true,
			width: '100%', 
		    height: '100%', 
		    checkbox: false,
		    rownumbers:true,
		    enabledSort:false,
		    pageSize:20,
		    //以下用于兼容后台的pagination
		    pageParmName:'currentPage',
		    pagesizeParmName:'pageSize',
		    root:'items',
		    record:'recordCount',
		    pageSize:30,
		    pageSizeOptions:[20,30,40,60,100],
		    onSuccess:function(data,grid){
		    	currentData = data;
		    },
		    onBeforeShowData:function(data){
		    	//用于支持多级取值方式绑定如name:'data.aa.dd.bcc'的方式
		    	function updateColumnData(column,grid){
		    		var name = column.columnname;
		    		if(name && name.indexOf('.')>0){
		    			if(data.items){
			       			 for(var i = 0; i < data.items.length; i++){
			       				updateColumnValueByName(data.items[i],column,grid.options.tree);
			       			 }
		    			}
		    		}
		    		if(column.columns && column.columns.length > 0){
		    			for(var i = 0; i < column.columns.length;i++){
		    				updateColumnData(column.columns[i],grid);
		    			}
		    		}
		    	}
		    	function updateColumnValueByName(rowdata,column,tree){
		    		var name = column.columnname;
		    		if(name && name.indexOf('.')>0){
		    			var names = name.split('.');
		    			var tmp = rowdata;
		    			for(var i = 0;i < names.length; i++){
		    				if(tmp[names[i]]!=null){
		    					tmp = tmp[names[i]];
		    				}else{
		    					tmp = null;
		    					break;
		    				}
		    			}
		    			rowdata[name] = tmp;
		    			if(tree){
		    				var children = rowdata[tree.childrenName];
		    				if(children && children.length > 0){
		    					for(var j = 0; j < children.length; j++){
		    						updateColumnValueByName(children[j],column,tree);
		    					}
		    				}else{
		    					if(tree.childrenName in rowdata){
		    						delete rowdata[tree.childrenName];
		    					}
		    				}
		    			}
		    		}
		    	}
		    	if(this.columns){
		    		for(var i = 0; i < this.columns.length;i++){
		    			updateColumnData(this.columns[i],this);
		    		}
		    	}
		    	return true;
		    },
		    onDblClickRow:function(rowData,rowIndex,rowDomElement){
		    	viewRow(rowData);
		    }
		},
		toolBarRender:null,//toolBar渲染
		dataType:''//数据类型名称
	},
	_init:function(options){
		this.opt = $.extend({},options||{});
		var o = this.opt;
		if(o.toolBarRender && typeof(o.toolBarRender)=='function'){
			this.toolBar = o.toolBarRender.call(null);
		}
		if(o.gridRender && typeof(o.gridRender)=='function'){
			this.grid = o.gridRender.call(null,gridOptions);
		}
		return this;
	},
	addRow:function(){
		var o = this.opt;
		if(o.add && o.add.url){
			var paramStr = '';
			if(o.add.url.indexOf('?')>0){
				paramStr = '&VIEWSTATE=ADD';
			}else{
				paramStr = '?VIEWSTATE=ADD';
			}
			if(typeof(o.add.beforeAdd)=='function'){
				var param = o.add.beforeAdd.call(null);
				if(param === false){
					return;
				}
				if(param){
					for(var p in param){
						paramStr = paramStr + '&' + p + '=' + param[p];
					}
				}
			}
			var flag = true;
			var dlg = art.dialog.open(o.add.url+paramStr,
					{title:"新增"+o.dataType,
					 lock:true,
					 width:o.add.width || 'auto',
					 height:o.add.height ||'auto',
					 id:o.dateType+"-ADD",
					 button:[{name:'确定',callback:function(){
							if(dlg.iframe.contentWindow && dlg.iframe.contentWindow.saveAdd){
								dlg.iframe.contentWindow.saveAdd(dlg);
							}
							return false;
						}},{name:'取消',callback:function(){
							flag = false;
							return true;
						}}],
					 close:function(){
						 if(flag){
							 if(typeof(o.add.afterAdd)=='function'){
								 o.add.afterAdd.call(null);
							 }
							 search(o.params);
						 }
					 }
					});
		}
	},
	editRow:function(){
		
	},
	viewRow:function(){
		
	},
	refresh:function(){
		
	},
	search:function(params){
		var p = this.params || {};
		$.extend(p,params||{});
	}
});